from pyecharts import Bar
import pandas as pd
import numpy as np



class ChipotleNan:

    def __init__(self):
        self.csv_name = r'C:\Users\关亮亮\Desktop\1807c_ana\DataAnalysis\c2/chipotle.csv'

        self.df = pd.read_csv(self.csv_name, sep=r'\t', engine='python')

        # 传入参数，获取你先还要的图的对象
    def bar(self, axis0, axis1, name='text', add_name=None):
        """
        :param axis0:     X轴
        :param axis1:     Y轴
        :param name:      图标的名字
        :param add_name:
        :return:      一个图标对象
        """
        bar = Bar(name)

        bar.add(add_name, axis0, axis1, is_label_show=True, is_datazoom_show=True)

        return bar



    # 求每种商品卖的总数
    #——————————————
    #返回应该包含信息的   Series对象
    def how_many_are_sold_per_item(self):

        df1 = self.df.groupby('item_name').sum().quantity

        return df1


    #每种商品的卖的总金额
    #——————————————
    #返回应该包含每个商品总价的信息的   DataFrame对象
    def the_total_price_of_each_item(self):

        item_price = self.df['item_price'].str.replace('$', '').astype('float64')

        df1 = pd.DataFrame({'item_name': self.df.item_name,
                            'item_price': item_price})           #生成一个新的DataFrame对象

        df2 = np.round(df1.groupby('item_name').sum(), 2)

        return df2


    def biao_three(self):  #超过10美元的商品单价

        df1 = self.df[['quantity', 'item_name', 'item_price']]

        df1.item_price = df1.item_price.str.replace("$", "").astype('float')
        df2 = df1.drop_duplicates(['item_name'])    # drop_duplicates  去重
        df2 = df2[df2.quantity == 1]
        df2 = df2[df2.item_price >= 10]
        df2.drop('quantity', axis=1, inplace=True)
        df3 = pd.DataFrame({'item_price': df2.item_price.values}, index=df2.item_name)

        return df3


    def biao_four(self):     #每件商品的单价

        df1 = self.df[['quantity', 'item_name', 'item_price']]

        df1.item_price = df1.item_price.str.replace("$", "").astype('float')

        df1 = df1.groupby('item_name').sum()

        df2 = pd.Series(round(df1.item_price/df1.quantity, 2), index=df1.index)

        return df2



    #Euro  数据分析

    def euro_biao_1(self):
        pass









